﻿using FEM.Result;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PBSD_Development
{
    /// <summary>
    /// 节点列表
    /// </summary>
    public class NodeSet
    {
        /// <summary>
        /// 节点列表
        /// </summary>
        private Dictionary<int, NodeObj> nodeDict { set; get; }

        /// <summary>
        /// 获得节点
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        public bool GetNode(int ID, out NodeObj node)
        {
            //初始化
            node = new NodeObj();
            //判断节点是否存在
            if (!this.nodeDict.ContainsKey(ID)) return false;
            //返回目标节点
            node =  this.nodeDict[ID];
            return true;
        }

        /// <summary>
        /// 最大包围框的X向长度
        /// </summary>
        /// <returns></returns>
        public double BoundaryXLength()
        {
            //所有坐标列表
            var xList = (from node in this.nodeDict.Values select node.X);
            return xList.Max() - xList.Min();
        }

        /// <summary>
        /// 最大包围框的Y向长度
        /// </summary>
        /// <returns></returns>
        public double BoundaryYLength()
        {
            //所有坐标列表
            var yList = (from node in this.nodeDict.Values select node.Y);
            return yList.Max() - yList.Min();
        }

        /// <summary>
        /// 最大包围框的Z向长度
        /// </summary>
        /// <returns></returns>
        public double BoundaryZLength()
        {
            //所有坐标列表
            var zList = (from node in this.nodeDict.Values select node.Z);
            return zList.Max() - zList.Min();
        }

        /// <summary>
        /// 构造节点列表
        /// </summary>
        /// <param name="result"></param>
        public NodeSet(FEMResult result)
        {
            //实例化
            this.nodeDict = new Dictionary<int, NodeObj>();
            //遍历构造节点
            result.GlobalResult.Nodes.Nodes.ForEach(node =>
            {
                this.nodeDict.Add(node.ID, new NodeObj(node));
            });
        }

    }
}
